﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:x="http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key">
  
  <!-- Define decimal format -->
  <xsl:decimal-format name="pt-br-Decimal" grouping-separator="." digit="#" zero-digit="0" decimal-separator="," />

  
  <xsl:variable name="ServerURL" select="/ProjectPerformanceDataSet/General/ServerURL"/>

  <xsl:variable name="member" select="/ProjectPerformanceDataSet/General/SelectedMember"/>

  <xsl:variable name="totalProjects" select="count(/ProjectPerformanceDataSet/ProjectPerformance)" />

  <xsl:variable name="currentSprintNumber" select ="/ProjectDataSet/Project/Sprint[SprintUId = /ProjectDataSet/Project/CurrentSprintUId]/SprintNumber"/>
  <xsl:variable name="currentPlanSprintUId" select ="/ProjectDataSet/Project/Sprint[SprintNumber = /ProjectDataSet/Project/Baseline]/SprintUId"/>


  <xsl:include href="../../Style.xslt"/>  


  <xsl:template name="IndicatorsHeader">

    <TableCell Style="{{StaticResource NoBorderCell}}">
      <Paragraph Style="{{StaticResource ParagraphCenter}}">
        % Year Income
      </Paragraph>
    </TableCell>
    <TableCell Style="{{StaticResource NoBorderCell}}">
      <Paragraph Style="{{StaticResource ParagraphCenter}}">
        % Burned Budget
      </Paragraph>
    </TableCell>
    <TableCell Style="{{StaticResource NoBorderCell}}" BorderBrush="#FF0000">
      <Paragraph Style="{{StaticResource ParagraphCenter}}">
        Hours Ahead/Late
      </Paragraph>
    </TableCell>
    <TableCell Style="{{StaticResource NoBorderCell}}">
      <Paragraph Style="{{StaticResource ParagraphCenter}}">
        % Quality
      </Paragraph>
    </TableCell>
    <TableCell Style="{{StaticResource NoBorderCell}}">
      <Paragraph Style="{{StaticResource ParagraphCenter}}">
        Velocity (pts/hrs)
      </Paragraph>
    </TableCell>

  </xsl:template>

  <xsl:template name="ProjectPerformance">
    <xsl:variable name="rowBG">
      <xsl:choose>
        <xsl:when test="IncomeRank=0">#FFFFFF</xsl:when>
        <xsl:when test="IncomeRank=1 or IncomeRank=2">#EEFFDD</xsl:when>
        <xsl:otherwise>#DDEECC</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <TableRow Background="{$rowBG}">
      <TableCell Style="{{StaticResource NoBorderCell}}" BorderBrush="{$rowBG}" ColumnSpan="6">
        <Paragraph Style="{{StaticResource SubTitleParagraph}}">
          <xsl:value-of select="ClientName"/> - <xsl:value-of select="ProjectName"/> [<xsl:value-of select="ProjectNumber"/>]
          <xsl:if test="Status=9">
            <TextBlock Foreground="#FF0000">CANCELED</TextBlock>
          </xsl:if>
          <xsl:if test="Status=10">
            <TextBlock Foreground="#FF0000">SUSPENDED</TextBlock>
          </xsl:if>
        </Paragraph>
      </TableCell>
    </TableRow>


    <TableRow Background="{$rowBG}">
      <TableCell Style="{{StaticResource SingleLineCell}}" RowSpan="2">
        <Paragraph>
          <xsl:value-of select="StartDateString"/>
          <xsl:choose>
            <xsl:when test="EndDate">
              - <xsl:value-of select="EndDateString"/>
            </xsl:when>
            <xsl:otherwise>
              - <xsl:value-of select="EstimatedEndDateString"/>
            </xsl:otherwise>
          </xsl:choose>
        </Paragraph>
        <Paragraph Margin="0,1,0,8">
          <xsl:variable name="projectUId" select="ProjectUId"/>
          <Bold>Team:</Bold>
          <xsl:for-each select="/ProjectPerformanceDataSet/ProjectRole[ProjectUId=$projectUId]">
            <xsl:sort select="UnitName"/>
            <xsl:value-of select="ContactName"/> (<xsl:value-of select="UnitName"/>),
          </xsl:for-each>
        </Paragraph>
      </TableCell>
      <xsl:call-template name="IndicatorsHeader" />

    </TableRow>

    <TableRow Background="{$rowBG}">

      <TableCell Style="{{StaticResource SingleLineCell}}" >
        <Paragraph Style="{{StaticResource BigParagraphCenter}}">
          <xsl:value-of select="format-number(PctIncome,'#.##0,0','pt-br-Decimal')"/>
        </Paragraph>
      </TableCell>
      <TableCell Style="{{StaticResource SingleLineCell}}" >
        <xsl:variable name="indFg1">
          <xsl:choose>
            <xsl:when test="PctBudgetBurned &gt;= 100">#FF0000</xsl:when>
            <xsl:otherwise>#000000</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <Paragraph Style="{{StaticResource SubTitleParagraphCenter}}" Foreground="{$indFg1}">
          <xsl:value-of select="format-number(PctBudgetBurned,'#.##0,0','pt-br-Decimal')"/>
        </Paragraph>
      </TableCell>
      <TableCell Style="{{StaticResource SingleLineCell}}" >
        <xsl:variable name="indFg2">
          <xsl:choose>
            <xsl:when test="HoursAhead &lt;= 0">#FF0000</xsl:when>
            <xsl:otherwise>#000000</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <Paragraph Style="{{StaticResource SubTitleParagraphCenter}}" Foreground="{$indFg2}">
          <xsl:value-of select="format-number(HoursAhead,'#.##0,0','pt-br-Decimal')"/>
        </Paragraph>
      </TableCell>
      <TableCell Style="{{StaticResource SingleLineCell}}">
        <xsl:variable name="indFg3">
          <xsl:choose>
            <xsl:when test="PctBugEffort &gt;= 10">#FF0000</xsl:when>
            <xsl:otherwise>#000000</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <Paragraph Style="{{StaticResource SubTitleParagraphCenter}}" Foreground="{$indFg3}">
          <xsl:value-of select="format-number(PctBugEffort,'#.##0,0','pt-br-Decimal')"/>
        </Paragraph>
      </TableCell>
      <TableCell Style="{{StaticResource SingleLineCell}}">
        <Paragraph Style="{{StaticResource SubTitleParagraphCenter}}">
          <xsl:value-of select="format-number(Velocity,'#.##0,0','pt-br-Decimal')"/>
        </Paragraph>
      </TableCell>
    </TableRow>
  </xsl:template>

  <xsl:template name="Summary">
    

    <Paragraph Style="{{StaticResource TitleParagraph}}">
      <xsl:if test="$member">
        <xsl:value-of select="/ProjectPerformanceDataSet/General/SelectedMemberName"/>&#160;
      </xsl:if>
      <xsl:value-of select="/ProjectPerformanceDataSet/General/SelectedYear"/> Year summary (<xsl:value-of select="$totalProjects"/> projects)
    </Paragraph>
    <Table Style="{{StaticResource NoBorderTable}}">
      <Table.Columns>
        <TableColumn Width="300"  />
        <TableColumn />
        <TableColumn />
        <TableColumn />
        <TableColumn />
        <TableColumn />
      </Table.Columns>
      <TableRowGroup>

        <TableRow>
          <TableCell Style="{{StaticResource SingleLineCell}}" RowSpan="2" >
            <Paragraph>


              <xsl:if test="$member">
                <Image Source="{$ServerURL}/FactoryService/MemberImage.aspx?memberId={$member}" Stretch="Fill" Width="50" Height="50" HorizontalAlignment="Center" Margin="5" />
              </xsl:if>

            </Paragraph>
          </TableCell>
          <xsl:call-template name="IndicatorsHeader" />
        </TableRow>


        <TableRow>
          <TableCell Style="{{StaticResource SingleLineCell}}">
            <Paragraph Style="{{StaticResource BigParagraphCenter}}">
              <xsl:value-of select="format-number(sum(/ProjectPerformanceDataSet/ProjectPerformance/PctIncome),'#.##0,0','pt-br-Decimal')"/>
            </Paragraph>
          </TableCell>
          <TableCell Style="{{StaticResource SingleLineCell}}">
            <xsl:variable name="PctBudgetBurnedAVG">
              <xsl:choose>
                <xsl:when test="$totalProjects &gt; 0">
                  <xsl:value-of select="sum(/ProjectPerformanceDataSet/ProjectPerformance/PctBudgetBurned) div $totalProjects"/>
                </xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <Paragraph Style="{{StaticResource SubTitleParagraphCenter}}">
              <xsl:value-of select="format-number($PctBudgetBurnedAVG,'#.##0,0','pt-br-Decimal')"/>
            </Paragraph>
          </TableCell>
          <TableCell Style="{{StaticResource SingleLineCell}}">
            <xsl:variable name="HoursAheadAVG">
              <xsl:choose>
                <xsl:when test="$totalProjects &gt; 0">
                  <xsl:value-of select="sum(/ProjectPerformanceDataSet/ProjectPerformance/HoursAhead) div $totalProjects"/>
                </xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <Paragraph Style="{{StaticResource SubTitleParagraphCenter}}">
              <xsl:value-of select="format-number($HoursAheadAVG,'#.##0,0','pt-br-Decimal')"/>
            </Paragraph>
          </TableCell>
          <TableCell Style="{{StaticResource SingleLineCell}}">
            <xsl:variable name="PctBugEffortAVG">
              <xsl:choose>
                <xsl:when test="$totalProjects &gt; 0">
                  <xsl:value-of select="sum(/ProjectPerformanceDataSet/ProjectPerformance/PctBugEffort) div $totalProjects"/>
                </xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <Paragraph Style="{{StaticResource SubTitleParagraphCenter}}">
              <xsl:value-of select="format-number($PctBugEffortAVG,'#.##0,0','pt-br-Decimal')"/>
            </Paragraph>
          </TableCell>
          <TableCell Style="{{StaticResource SingleLineCell}}">
            <xsl:variable name="VelocityAVG">
              <xsl:choose>
                <xsl:when test="$totalProjects &gt; 0">
                  <xsl:value-of select="sum(/ProjectPerformanceDataSet/ProjectPerformance/Velocity) div $totalProjects"/>
                </xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <Paragraph Style="{{StaticResource SubTitleParagraphCenter}}">
              <xsl:value-of select="format-number($VelocityAVG,'#.##0,0','pt-br-Decimal')"/>
            </Paragraph>
          </TableCell>
        </TableRow>
      </TableRowGroup>

    </Table>
  </xsl:template>

</xsl:stylesheet>

